//
//  ChangeAddressViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/14.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "ChangeAddressViewController.h"
#import "NavView.h"
#import "MyTagView.h"
#import "AddressPickerView.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface ChangeAddressViewController ()<UITextFieldDelegate,UITextViewDelegate,AddressPickerViewDelegate>
@property (nonatomic,strong) NSArray *dataAray;
@property (nonatomic,strong) UITextView *detailView2;
@property (nonatomic,strong) UILabel *placeholderLable;
@property (nonatomic,strong) AddressPickerView * pickerView;


@end

@implementation ChangeAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NavView *nav = [[NavView alloc]initWithTitle:@"修改收货地址" LeftImage:[ UIImage imageNamed:@"1223"]];
    nav.frame = CGRectMake(0, 20, kScreenW, 44);
    nav.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    nav.titleLable.textColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    [nav.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nav];
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kScreenW, kScreenH-64)];
    backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0f];
    [self.view addSubview:backgroundView];
    UIView *nameView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 100*kScale)];
    nameView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:nameView];
    UITextField *nameField = [[UITextField alloc]init];
    nameField.delegate = self;
    nameField.font = [UIFont systemFontOfSize:15];
    nameField.placeholder = @"请输入收货人姓名";
    nameField.frame = CGRectMake(30*kScale, 0, kScreenW, 100*kScale);
    [nameView addSubview:nameField];
    UIView *phoneView = [[UIView alloc]initWithFrame:CGRectMake(0, 102*kScale, kScreenW, 100*kScale)];
    phoneView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:phoneView];
    UITextField *phoneField = [[UITextField alloc]init];
    phoneField.delegate = self;
    phoneField.font = [UIFont systemFontOfSize:15];
    
    phoneField.placeholder = @"请输入手机号码";
    phoneField.frame = CGRectMake(30*kScale, 0, kScreenW, 100*kScale);
    [phoneView addSubview:phoneField];
    
    UIView *addressView = [[UIView alloc]initWithFrame:CGRectMake(0, 204*kScale, kScreenW, 100*kScale)];
    addressView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:addressView];
    UILabel *addressLable = [[UILabel alloc]init];
    addressLable.font = [UIFont systemFontOfSize:15];
    
    addressLable.text = @"所在地区";
    addressLable.frame = CGRectMake(30*kScale, 0, kScreenW, 100*kScale);
    [addressView addSubview:addressLable];
    
    UILabel *addLable = [[UILabel alloc]init];
    addLable.font = [UIFont systemFontOfSize:15];
    
    addLable.text = @"请选择";
    addLable.textAlignment = NSTextAlignmentRight;
    addLable.frame = CGRectMake(30*kScale, 0, kScreenW-102*kScale-20*kScale, 100*kScale);
    [addressView addSubview:addLable];
    UIImageView *btnImg = [[UIImageView alloc]init];;
    btnImg.frame = CGRectMake(kScreenW-30*kScale-42*kScale, 29*kScale, 42*kScale, 42*kScale);
    btnImg.image = [UIImage imageNamed:@"右边"];
    [addressView addSubview:btnImg];
    UIButton *selectAddressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selectAddressBtn.frame = addressView.frame;
    [selectAddressBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:selectAddressBtn];

    
    
    UIView *detailView = [[UIView alloc]initWithFrame:CGRectMake(0, 306*kScale, kScreenW, 280*kScale)];
    detailView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:detailView];
    _detailView2 = [[UITextView alloc]init];
    _detailView2.frame = CGRectMake(26*kScale, 306*kScale, kScreenW, 280*kScale);
    _detailView2.delegate = self;
    _detailView2.font = [UIFont systemFontOfSize:15];
    [backgroundView addSubview:_detailView2];
    
    _placeholderLable = [[UILabel alloc]init];
    _placeholderLable.text = @"请填写详细地址";
    _placeholderLable.textColor = [UIColor colorWithRed:158/255.0 green:158/255.0 blue:158/255.0 alpha:1.0f];
    _placeholderLable.font = [UIFont systemFontOfSize:15];
    _placeholderLable.frame = CGRectMake(4*kScale, 0, kScreenW-60*kScale, 70*kScale);
    [_detailView2 addSubview:_placeholderLable];
    
    UIView *setView = [[UIView alloc]initWithFrame:CGRectMake(0, (306+280+20)*kScale, kScreenW, 100*kScale)];
    setView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:setView];
    UILabel *setLable = [[UILabel alloc]init];
    setLable.font = [UIFont systemFontOfSize:15];
    
    setLable.text = @"设置为默认";
    setLable.frame = CGRectMake(30*kScale, 0, kScreenW, 100*kScale);
    [setView addSubview:setLable];
    
    UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(kScreenW-60*kScale-70*kScale, 29*kScale, 70*kScale, 42*kScale)];
    switchButton.center = CGPointMake(kScreenW-30*kScale-(switchButton.frame.size.width)/2, 50*kScale);
    [switchButton setOn:YES];
    [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [setView addSubview:switchButton];
    [self.view addSubview:self.pickerView];
}
- (AddressPickerView *)pickerView{
    if (!_pickerView) {
        _pickerView = [[AddressPickerView alloc]initWithFrame:CGRectMake(0,kScreenH, kScreenW, 215)];
        _pickerView.delegate = self;
    }
    return _pickerView;
}
-(void)textViewDidChange:(UITextView*)textView
{
    
    if([_detailView2.text length] == 0){
        
        _placeholderLable.text = @"请填写详细地址";
        
    }else{
        
        _placeholderLable.text = @"";//这里给空
        
    }
}
- (void)btnClick:(UIButton *)btn{
    [UIView animateWithDuration:0.5 animations:^{
        
        [UIView beginAnimations:@"move" context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];
        //改变它的frame的x,y的值
        if (btn.selected) {
            _pickerView.frame = CGRectMake(0, kScreenH, kScreenW, 215);
        }
        else {
            _pickerView.frame=CGRectMake(0,kScreenH - 215, kScreenW,215);
        }
        [UIView commitAnimations];
        
        btn.selected = !btn.selected;
        
    }];
}

#pragma mark - AddressPickerViewDelegate
- (void)cancelBtnClick{
    NSLog(@"点击了取消按钮");
    [self btnClick:nil];
}
- (void)sureBtnClickReturnProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area{
    [self btnClick:nil];
}


-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
    }else {
    }
}

- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
